{extend name="public/list_page"/}
{block name="content"}
<div class="layui-card">
    <div class="layui-card-body">
        <table class="layui-table" id="historyList" lay-filter="list"></table>
    </div>
</div>
{/block}

{block name="custom"}
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="addHistory"><i class="layui-icon">&#xe654;</i>添加</button>
    </div>
</script>

<script type="text/html" id="barHandle">
    <button type="button" class="layui-btn handel-btn layui-btn-primary" lay-event="edit" title="编辑"><i class="layui-icon">&#xe642;</i></button>
    <button type="button" class="layui-btn handel-btn layui-btn-del" lay-event="del" title="删除"><i class="layui-icon">&#xe640;</i></button>
</script>
{/block}

{block name="js"}
<script>
    layui.use(['table','form'], function() {
        var table = layui.table;
        var form = layui.form;

        var historyList = table.render({
            title: '',
            elem: "#historyList",
            method: "post",
            url: "{:url('company/history')}",
            page: true,
            limits: [10, 25, 50, 100, 200, 300, 400, 500, 1000],
            toolbar: "#toolbar",//开启头部工具栏
            defaultToolbar:[],
            response: {
                statusCode: 'suc'
            },
            cols: [[
                {field: 'year', title: '年份', align: 'center'},
                {field: 'content', title: '内容', align: 'center'},
                {field: 'sort', title: '排序', align: 'center'},
                {field: '', title: '操作', align: 'center', toolbar: '#barHandle'}
            ]],
            done:function (res, curr, count) {
                historyCurrPage = curr
                $('.layui-table-cell').css({'height':'auto'})
            }
        });

        //头部工具栏事件
        table.on('toolbar(list)',function (obj) {
            if (obj.event == 'addHistory') {
                xadmin.open('添加','{:url("company/addHistory")}')
            }
        });

        // 监听工具列点击事件
        table.on('tool(list)',function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                let id = data.id
                let url = "{:url('company/editHistory')}?id="+id
                xadmin.open('编辑',url)
            }else if (obj.event == 'del') {
                layer.confirm('确认删除？',{title:''},function (index) {
                    ajaxRequest("{:url('company/delHistory')}",{id:data.id},function (res) {
                        let icon = 2;
                        if (res.code == 'suc') {
                            icon = 1;
                        }
                        layer.msg(res.msg,{icon:icon,time:1000},function () {
                            historyList.reload()
                        });
                        layer.close(index);
                    })
                })
            }
        });
    });
</script>
{/block}